using System;
using System.Data;
using istIUniDB;

namespace Shraga.BLL
{
	/// <summary>
	/// Gives access to all the note types tables.
	/// </summary>
	public class NoteTypes
	{	
		public NoteTypes() {}

		#region Types Listing

		/// <summary>
		/// Returns all the sources DataTable with "ID", "NAME".
		/// </summary>
		public DataTable Sources
		{
			get 
			{
				IUniDB udb = UniDBSingleton.Instance().UniDB;						

				// Returns the list of sources
				return (udb.RunSQLReturnDataTable("SELECT ID, NAME " + 
												  "FROM   note_source"));
										
			}
		}
		/// <summary>
		/// Returns all the types DataTable with "ID", "NAME".
		/// </summary>
		public DataTable Types
		{
			get 
			{
				IUniDB udb = UniDBSingleton.Instance().UniDB;						

				// Returns the list of sources
				return (udb.RunSQLReturnDataTable("SELECT ID, NAME " + 
												  "FROM   note_type"));
										
			}
		}
		/// <summary>
		/// Returns all the closes DataTable with "ID", "NAME".
		/// </summary>
		public DataTable Closes
		{
			get 
			{
				IUniDB udb = UniDBSingleton.Instance().UniDB;						

				// Returns the list of sources
				return (udb.RunSQLReturnDataTable("SELECT ID, NAME " + 
												  "FROM   note_close"));
										
			}
		}


		#endregion
	
		#region Types API

		/// <summary>
		/// Returns a source name by its id
		/// </summary>
		/// <param name="Id"></param>
		/// <returns></returns>
		public String SourceNameById(int Id)
		{
			IUniDB udb = UniDBSingleton.Instance().UniDB;						
			clsParameter[] arrParam = new clsParameter[1];
			arrParam[0] = new clsParameter(Id, OracleTypes.Int32);
			return (udb.RunSQLReturnString("SELECT NAME " + 
										   "FROM   note_source " +
										   "WHERE  id = :1", ref arrParam));						
		}

		/// <summary>
		/// Returns a note type name by its id
		/// </summary>
		/// <param name="Id"></param>
		/// <returns></returns>
		public String TypeNameById(int Id)
		{
			IUniDB udb = UniDBSingleton.Instance().UniDB;						
			clsParameter[] arrParam = new clsParameter[1];
			arrParam[0] = new clsParameter(Id, OracleTypes.Int32);
			return (udb.RunSQLReturnString("SELECT NAME " + 
										   "FROM   note_type " +
										   "WHERE  id = :1", ref arrParam));						
		}

		/// <summary>
		/// Returns a note close name by its id
		/// </summary>
		/// <param name="Id"></param>
		/// <returns></returns>
		public String CloseNameById(int Id)
		{
			IUniDB udb = UniDBSingleton.Instance().UniDB;						
			clsParameter[] arrParam = new clsParameter[1];
			arrParam[0] = new clsParameter(Id, OracleTypes.Int32);
			return (udb.RunSQLReturnString("SELECT NAME " + 
										   "FROM   note_close " +
										   "WHERE  id = :1", ref arrParam));						
		}
		
		#endregion

	}
}
